package com.sinosoft.dsp.platform.components.portal.input;

import com.sinosoft.builder.templates.concept.TagElementType;
import com.sinosoft.dsp.platform.components.portal.input.elements.ISinoTagElement;
import com.sinosoft.dsp.platform.exception.SinoPlatformException;

public class SinoDefaultTagElementBean {
	public static final String TEMPLATE_PREFIX = "/layout/input/elements/";
	public static final String TEMPLATE_SUFFIX = ".xhtml";

	private String elementId;

	private boolean invalid;

	private TagElementType type;

	private ISinoTagElement value;

	private boolean display;

	public String getElementId() {
		return elementId;
	}

	public SinoDefaultTagElementBean() {

	}

	public SinoDefaultTagElementBean(TagElementType type) {
		this.setElementId(type.getId()).setInvalid(false).setDisplay(
				type.isIsDisplay()).setType(type);
	}

	public SinoDefaultTagElementBean setElementId(String elementId) {
		this.elementId = elementId;
		return this;
	}

	public boolean isInvalid() {
		return invalid;
	}

	public SinoDefaultTagElementBean setInvalid(boolean invalid) {
		this.invalid = invalid;
		return this;
	}

	public TagElementType getType() {
		return type;
	}

	public SinoDefaultTagElementBean setType(TagElementType type) {
		this.type = type;
		return this;
	}

	public ISinoTagElement getValue() {
		return value;
	}

	public SinoDefaultTagElementBean setValue(ISinoTagElement value) {
		this.value = value;
		return this;
	}

	public boolean isDisplay() {
		return display;
	}

	public SinoDefaultTagElementBean setDisplay(boolean display) {
		this.display = display;
		return this;
	}

	public String getTemplate() throws SinoPlatformException {
		if (this.type == null && this.type.getTagType() == null) {
			throw new SinoPlatformException("获得模板出现错误");
		}
		return TEMPLATE_PREFIX + this.type.getTagType().value()
				+ TEMPLATE_SUFFIX;
	}
}
